//
//  BigWithDragImageView.m
//  TravelFirst
//
//  Created by lanou on 15/9/22.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "BigWithDragImageView.h"

@implementation BigWithDragImageView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.clipsToBounds = YES;
        
        self.userInteractionEnabled = YES;
        
        self.nicknameButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.nicknameButton.frame = CGRectMake(15 * kFrameWidthScale, (frame.size.height - 5 - 40) * kFrameHeightScale, 40 * kFrameWidthScale, 40 * kFrameHeightScale);
        self.nicknameButton.layer.masksToBounds = YES;
        self.nicknameButton.layer.cornerRadius = self.nicknameButton.width / 2;
        self.nicknameButton.backgroundColor = [UIColor redColor];
        self.nicknameButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        [self addSubview:self.nicknameButton];
        
        self.sourceLabel = [[UILabel alloc] initWithFrame:CGRectMake(70 * kFrameWidthScale, (frame.size.height - 33) * kFrameHeightScale, 295 * kFrameWidthScale, 20 * kFrameHeightScale)];
        self.sourceLabel.font = [UIFont boldSystemFontOfSize:12];
        self.sourceLabel.textColor = [UIColor whiteColor];
        self.sourceLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        [self addSubview:self.sourceLabel];
    }
    return self;
}

- (void)setValueWithModel:(NotesModel *)model
{
    [self sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:nil];
    [self.nicknameButton sd_setBackgroundImageWithURL:[NSURL URLWithString:model.avatar] forState:UIControlStateNormal placeholderImage:nil];
    if (model.source && model.source.length != 0) {
        self.sourceLabel.text = [NSString stringWithFormat:@"%@ 来源: %@", model.nickname, model.source];
    } else {
        self.sourceLabel.text = model.nickname;
    }
    
}


@end
